  package generation.makers;

import generation.scale.Scale;
import util.ConfigFile;
import util.Utils;

public class HarmonyMakerImpl implements HarmonyMaker {

	public static String getTuneRelChord(String chord){
		int index = chord.indexOf(">");
		String dominant = chord.substring(0,index+1);
		String chordType = chord.substring(index+1, chord.length());
		String third = "";
		if(chordType.equals("maj")){
			third = "<" + (Integer.parseInt(chord.substring(1,index)) + 4) + ">";
		} else {
			third = "<" + (Integer.parseInt(chord.substring(1,index)) + 3) + ">";
		}
		String fifth = "<" + (Integer.parseInt(chord.substring(1,index)) + 7) + ">";
		String[] arpeggio = {dominant, third, fifth};
		String tune = "";
		if(ConfigFile.getBoolean("harmony.arpeggio")){
			tune = arpeggio[Utils.random(arpeggio.length)];
		} else {
			tune = dominant;
		}
		return tune;
	}

	public static String generateChords(Scale scale){
		String ret = "";
		String[] chords = scale.getChords();
		String curChord = chords[Utils.random(chords.length)];
		ret = curChord;
		for (int i = 0; i < 3; i++) {
			/*String nextChord = "";
			if(curChord.equals(CHORD_C)){
				double chance = Math.random();
				if(chance < 0.1){
					nextChord = CHORD_C;
				} else if (chance < 0.3){
					nextChord = CHORD_G;
				} else {
					double chance2 = Math.random();
					if(chance2 < 0.5){
						nextChord = CHORD_Am;
					} else {
						nextChord = CHORD_Am;
					}
				}
			} else if(curChord.equals(CHORD_Am)){
				double chance = Math.random();
				if(chance < 0.1){
					nextChord = CHORD_Am;
				} else if (chance < 0.3){
					nextChord = CHORD_G;
				} else {
					double chance2 = Math.random();
					if(chance2 < 0.5){
						nextChord = CHORD_C;
					} else {
						nextChord = CHORD_C;
					}
				}
			} else if(curChord.equals(CHORD_F)){
				double chance = Math.random();
				if(chance < 0.1){
					nextChord = CHORD_F;
				} else if (chance < 0.3){
					nextChord = CHORD_G;
				} else {
					double chance2 = Math.random();
					if(chance2 < 0.5){
						nextChord = CHORD_Am;
					} else {
						nextChord = CHORD_C;
					}
				}
			} else {
				double chance = Math.random();
				if(chance < 0.1){
					nextChord = CHORD_G;
				} else if (chance < 0.3){
					nextChord = CHORD_F;
				} else {
					double chance2 = Math.random();
					if(chance2 < 0.5){
						nextChord = CHORD_Am;
					} else {
						nextChord = CHORD_C;
					}
				}
			}
			ret = ret + " " + nextChord;
			curChord = nextChord;*/
			ret = ret + " " + chords[Utils.random(chords.length)];
		}
		return ret;
	}

}
